#define CS_VREDRAW              1
#define CS_HREDRAW              2
#define CS_GLOBALCLASS     0x4000

#define CW_USEDEFAULT      0x8000

#define SW_NORMAL               1

#define WS_VISIBLE     0x10000000
#define WS_THICKFRAME  0x00040000
#define WS_MINIMIZEBOX 0x00002000

//----------------------------------------------------------------------------//

function TForm()

   static oClass

   if oClass == nil
      oClass = TClass():New( "TFORM" )

      oClass:AddData( "hWnd" )
      oClass:AddData( "bLClicked" )
      oClass:AddData( "oMenu" )

      oClass:AddClassData( "aWindows" )

      oClass:AddMethod( "New",         @New() )

      oClass:AddMethod( "LButtonDown", @LButtonDown() )
      oClass:AddMethod( "ShowModal",   @ShowModal() )
      oClass:AddMethod( "SetMenu",     @_SetMenu() )
      oClass:AddMethod( "SetText",     @SetText() )

      oClass:AddInline( "Test", { || "Inline method" } )

      oClass:AddVirtual( "Another" )

      oClass:Create()
   endif

return oClass:Instance()

//----------------------------------------------------------------------------//

static function New()

   local Self := QSelf()

   if ::aWindows == nil
      ::aWindows = {}
   endif

   if RegisterClass( "TFORM",;
                     nOr( CS_GLOBALCLASS, CS_VREDRAW, CS_HREDRAW ) )

      ::hWnd = CreateWindow( "TFORM", "Form",;
                             nOr( WS_THICKFRAME, WS_MINIMIZEBOX ),;
                             0, 0, CW_USEDEFAULT, CW_USEDEFAULT )

      AAdd( ::aWindows, Self )
      SetProp( ::hWnd, "FF", Len( ::aWindows ) )
      WindowsFix( ::aWindows )
   else
      MsgAlert( "Can't register TForm Class" )
   endif

return Self

//----------------------------------------------------------------------------//

static function LButtonDown( nRow, nCol, nFlags )

   local Self := QSelf()

   if ::bLClicked != nil
      return Eval( ::bLClicked, nRow, nCol, nFlags, Self )
   endif

return nil

//----------------------------------------------------------------------------//

static function SetText( cText )

   local Self := QSelf()

   SetWindowText( ::hWnd, cText )

return nil

//----------------------------------------------------------------------------//

static function ShowModal()

   local Self := QSelf()

   ShowWindow( ::hWnd, SW_NORMAL )
   WinRun( ::hWnd )

return nil

//----------------------------------------------------------------------------//

static function _SetMenu( oMenu )

   local Self  := QSelf()

   if ::oMenu != nil
   endif

   ::oMenu = oMenu
   SetMenu( ::hWnd, oMenu:hMenu )

return nil

//----------------------------------------------------------------------------//
